package com.gzz.orchid.common.webmvc.util;

import com.alibaba.fastjson2.JSON;
import com.gzz.orchid.common.webmvc.support.HttpResult;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;

import java.io.IOException;

/**
 * 响应工具类 ResponseUtil
 *
 * @author higmd
 */
public class RespUtil {
    private static final String CONTENT_TYPE = "application/json;charset=utf-8";

    public static void resolver(HttpServletResponse resp, HttpResult result) throws IOException {
        resp.setContentType(CONTENT_TYPE);
        resp.setStatus(HttpStatus.OK.value());
        //
        resp.getWriter().write(JSON.toJSONString(result));
        resp.getWriter().flush();
        resp.getWriter().close();
    }
}
